package com.nkzy.mapper;

import com.nkzy.pojo.Address;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper {

    /**
     * 插入一个新的地址记录
     * @param address 地址对象
     * @return 插入成功的记录数
     */
    @Insert("INSERT INTO address (id, user_id, province, city, town, mobile, street, contact, is_default, notes, deleted) " +
            "VALUES (#{id}, #{userId}, #{province}, #{city}, #{town}, #{mobile}, #{street}, #{contact}, #{isDefault}, #{notes}, #{deleted})")
    int insertAddress(Address address);

    /**
     * 更新指定ID的地址记录
     * @param address 地址对象
     * @return 更新成功的记录数
     */
    @Update("UPDATE address SET user_id = #{userId}, province = #{province}, city = #{city}, town = #{town}, mobile = #{mobile}, " +
            "street = #{street}, contact = #{contact}, is_default = #{isDefault}, notes = #{notes}, deleted = #{deleted} " +
            "WHERE id = #{id}")
    int updateAddress(Address address);

    /**
     * 删除指定ID的地址记录
     * @param id 地址ID
     * @return 删除成功的记录数
     */
    @Delete("DELETE FROM address WHERE id = #{id}")
    int deleteAddress(Long id);

    /**
     * 根据ID查询地址记录
     * @param id 地址ID
     * @return 地址对象
     */
    @Select("SELECT * FROM address WHERE id = #{id}")
    Address selectAddressById(Long id);

    /**
     * 查询所有地址记录
     * @return 地址对象列表
     */
    @Select("SELECT * FROM address")
    List<Address> selectAllAddresses();
}